
import {customRef} from 'vue'

export default function(initValue:any,delay:number){

    let msg = customRef((track,trigger)=>{
    let timer:number
        return {
            // msg被读取时调用
            get() {
                track()
                return initValue
            },
            // msg被修改时调用
            set(value){
                clearTimeout(timer)
                timer = setTimeout(() => {
                    initValue = value
                    trigger()
                }, delay);
            }
        }
    })

    return {msg}
}